package spring.cloud.study.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfig {
	
	/**
	 * @Title: customRouteLocator   
	 * @Description: 编码配置gateway规则
	 * 当访问localhost:9527/guonei 会自动转发到-->http://news.baidu.com/guonei
	 * @date: 2021年12月14日 下午5:02:21   
	 * @version:
	 * @param builder
	 * @return          
	 * @throws
	 */
	@Bean
	public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
		RouteLocatorBuilder.Builder routes = builder.routes();
		routes
			.route("route1", r -> r.path("/guonei").uri("http://news.baidu.com/guonei"))
			.route("route2",r->r.path("/guoji").uri("http://news.baidu.com/guoji"))
			.build();
		return routes.build();
	}
}
